/*version 20141002*/
/*变成句柄访问模式*/
/*ARM下非对齐访问是不允许的 x86允许  */

#pragma once

//#include "uartStdio.h"

#include "MutexLock.h"
#include <compile.h>
//#define _mch (volatile struct MCH)





struct MCB
{
	_ptlong used;
	_ptlong msize;
	MCB* next;
} __attribute__((packed));

struct MCH
{
	_ptlong* MEMORY_BASE;
	_ptlong MEMORY_SIZE;
	MCB* next;
	_mlock locker;
} __attribute__((packed));

typedef struct MCB _mcb;
typedef struct MCH _mch;



void MemoryControlInit(_mch* handle,_ptlong* memoryBase,_ptlong memorySize);

void* Kalloc(_mch* handle,_ptlong size);
void* Kmalloc(_mch* handle,_ptlong size);
void Kfree(_mch* handle, void* pointer);
void MemoryFlash(_mch* handle);

inline void* FLPageApply(_mch* handle); //pretested
inline void* SLPageApply(_mch* handle); //pretested
inline void* PageApply(unsigned int pagenum,_mch* handle); //pretested

#define NULL 		nullptr

extern volatile _mch kmemory;

